/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hxg.portmgr.core.oper.snmp.record;

import hxg.portmgr.core.device.intf.Intf;
import java.util.EnumMap;
import hxg.portmgr.core.oper.snmp.oidgroup.FlowOID;

/**
 * HC类的流量信息采集器,可以的话应作为第一选择使用
 * @author hxg
 */
public class FlowRecord {

    Intf intf;
    EnumMap<FlowOID, Long> ValueMap = new EnumMap(FlowOID.class);
    long logdate;

    public FlowRecord(Intf intf, EnumMap ValueMap, long logdate) {
        this.intf = intf;
        this.logdate = logdate;
        this.ValueMap = ValueMap;
    }

    public EnumMap getValueMap() {
        return ValueMap;
    }

    public Intf getIntf() {
        return intf;
    }

    public long getLogdate() {
        return logdate;
    }

    public EnumMap<FlowOID, Float> getFlow(FlowRecord otherFlowRecord) {
        return getFlow(otherFlowRecord, BandWidthMode.Kbps);
    }

    public EnumMap<FlowOID, Float> getFlow(FlowRecord otherFlowRecord, BandWidthMode bandWidthMode) {
        if (otherFlowRecord.getIntf().equals(intf)) {
            EnumMap<FlowOID, Float> mp = new EnumMap(FlowOID.class);
            for (FlowOID flowoid : FlowOID.values()) {
                if (this.ValueMap.containsKey(flowoid) && otherFlowRecord.ValueMap.containsKey(flowoid)) {
                    long dataIncr = otherFlowRecord.ValueMap.get(flowoid) - this.ValueMap.get(flowoid);
                    long bitIncr = dataIncr << 3; //原始数据是基于字节的,左移三位将其转换为bit,也方便后面的操作提高精度
                    long timeIncr = otherFlowRecord.getLogdate() - getLogdate();
                    float bitflow = bandWidthMode.bpsTransToThis((float) bitIncr / (float) timeIncr);
                    mp.put(flowoid, bitflow);
                } else {
                    //mp.put(flowoid, -1f);
                }
            }
            return mp;
        }
        return new EnumMap(FlowOID.class);
    }

    @Override
    public String toString() {
        return super.toString();
    }
    
    
}
